package com.pet.behavior.listener;

import com.pet.behavior.service.ApFollowBehaviorService;
import com.pet.common.constants.MQConstants;
import com.pet.model.behavior.dtos.FollowBehaviorDto;
import com.pet.utils.common.JsonUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class FollowBehaviorListener {
    @Autowired
    private ApFollowBehaviorService apFollowBehaviorService;

    @KafkaListener(topics = MQConstants.FOLLOW_BEHAVIOR_TOPIC)
    public void handleMsg(ConsumerRecord consumerRecord){
        if(consumerRecord!=null){
            String value= (String) consumerRecord.value();
            FollowBehaviorDto followBehaviorDto = JsonUtils.toBean(value, FollowBehaviorDto.class);

            apFollowBehaviorService.saveFollowBehavior(followBehaviorDto);
        }
    }
}
